<?php

 namespace app\index\service;

 use think\Db;

 /**
  * @author xjy
  */
class DeliveryfollowService
 {

     //国家仓在途明细列表
     static public function getList($param)
     {
         if(empty($param['down'])){
              $titles=[];
         }else{
              $titles=[
                   'code'=>'配送计划单号','business_code'=>'业务单号','type'=>'类型','sku'=>'SKU','sku_name'=>'中文名称','quantity'=>'配送数量','company_str_out'=>'调出公司',
                  'shop_str_rec'=>'调入店铺','warequantity'=>'入库数量','waredate'=>'入库时间','warehouse_str_out'=>'调出仓库','warehouse_str_rec'=>'调入店仓',
                  'differ_num'=>'差异数'];
         }
        return \app\index\model\DeliveryfollowModel::getList($param,$titles,"app\index\service\DeliveryfollowService::convertData");
     }
     public static function convertData($data){
         $warehouse=\app\common\ConfigBase::getWarehouseAll();
         $shop=\app\common\ConfigBase::getShopAll();
         $company=\app\common\ConfigBase::getCompanyAll();
         $code=array_column($data,'code');
         if($data){
             foreach($data as $key=>&$value){
                $value['warehouse_str_out']=isset($warehouse[$value['warehouse_id_out']]) ? $warehouse[$value['warehouse_id_out']]:'';
                $value['warehouse_str_rec']=isset($warehouse[$value['warehouse_id_rec']]) ? $warehouse[$value['warehouse_id_rec']]:'';
                $value['company_str_out']=isset($company[$value['company_id_out']]) ? $company[$value['company_id_out']]:'';
                $value['shop_str_rec']=isset($shop[$value['shop_id_rec']]) ? $shop[$value['shop_id_rec']]:'';
                $value['differ_num']=$value['quantity']-$value['warequantity'];
                $value['type_code']=$value['type'];
                $value['type']=($value['type']==1) ? '调拨' :"采销";
                $value['business_code']=$value['allocate_order_sn'];
             }
         }
         return $data;
     }
 }
